<?php

class WebUser extends CWebUser
{
	// ------------------------------------------------------------------------------------

	protected $_User = NULL;
	protected $_Pool = NULL;

	// ------------------------------------------------------------------------------------
	/**
	 * @return null
	 */
	public function getUser()
	{
		if(NULL === $this->_User)
		{
			if(!empty($this->id))
			{
				$this->_User = UsersLib::i()->find(array('user_id' => $this->id));
			}
		}
		return $this->_User;
	}

	// ------------------------------------------------------------------------------------
	/**
	 * @return bool|Pool
	 */
	public function getPool()
	{
		if(NULL === $this->_Pool)
		{
			$User = $this->getUser();
			if(!empty($User))
			{
				$this->_Pool = new Pool();
				if(!empty($User->user_pool))
				{
					$this->_Pool->import($User->user_pool);
				}
				else
				{
					$this->_Pool->generate();
					$User->user_pool = $this->_Pool->export();
					$User->save();
				}
			}
		}
		return $this->_Pool;
	}

	// ------------------------------------------------------------------------------------
}